/*
 * Copyright (c) Jipzingking 2016.
 */

package sdfs.client;

import sdfs.namenode.LocatedBlock;
import sdfs.namenode.NameNode;
import sdfs.namenode.SDFSFileChannel;
import sdfs.protocol.INameNodeProtocol;

import java.io.IOException;
import java.util.List;
import java.util.UUID;

public class NameNodeStub implements INameNodeProtocol {
    public INameNodeProtocol nameNode;

    public NameNodeStub()throws Exception{
        //this.nameNode= Rpc.refer(INameNodeProtocol.class,"127.0.0.1", NameNode.NAME_NODE_PORT);
        this.nameNode=new NameNode();
    }
    //public NameNode nameNode = NameNode.getInstance();

    @Override
    public SDFSFileChannel openReadonly(String fileUri) throws IOException {
        return nameNode.openReadonly(fileUri);
    }

    @Override
    public SDFSFileChannel openReadwrite(String fileUri) throws IndexOutOfBoundsException, IllegalStateException, IOException {
        return nameNode.openReadwrite(fileUri);
    }

    @Override
    public SDFSFileChannel create(String fileUri) throws IllegalStateException, IOException {
        return this.nameNode.create(fileUri);
    }

    @Override
    public void closeReadonlyFile(UUID fileUuid) throws IllegalStateException, IOException {
        nameNode.closeReadonlyFile(fileUuid);
    }

    ///后面看要求补做
    @Override
    public void closeReadwriteFile(UUID fileUuid, int newFileSize) throws IllegalStateException, IllegalArgumentException, IOException {
        nameNode.closeReadwriteFile(fileUuid,newFileSize);
    }

    @Override
    public void mkdir(String fileUri) throws IOException {
        nameNode.mkdir(fileUri);
    }

    @Override
    public LocatedBlock addBlock(UUID fileUuid) {
        return nameNode.addBlock(fileUuid);
    }

    @Override
    public List<LocatedBlock> addBlocks(UUID fileUuid, int blockAmount) {
        return nameNode.addBlocks(fileUuid,blockAmount);
    }

    @Override
    public void removeLastBlock(UUID fileUuid) throws IllegalStateException {
        nameNode.removeLastBlock(fileUuid);
    }

    @Override
    public void removeLastBlocks(UUID fileUuid, int blockAmount) throws IllegalStateException {
        nameNode.removeLastBlocks(fileUuid,blockAmount);
    }
}
